<?php
/**
 * Created by PhpStorm.
 * User: stone
 * Date: 2017/4/15
 * Time: 1:04
 */

namespace app\api\model;


use think\Model;

class Order extends Model
{
    function goods($OrderId)
    {
        return db('order_goods')->where('OrderId', $OrderId)->select();
    }

    public function getStatusAttr($value)
    {
        $status = [-2 => '已取消', -1 => '商家取消', 0 => '未支付', 1 => '已支付', 2 => '已确认', 3 => '待配送', 4 => '配送中', 5 => '待评价', 6 => '已完成'];
        return $status[$value];
    }

    public function cost($OrderId)
    {
        $goods = $this->goods($OrderId);
        $p = 0;
        foreach ($goods as $k => $v) {
            $p += $v['Price'];
        }
        return $p;
    }

    public function address()
    {
        return db('user_address')->where("Id", $this->Address)->find();
    }

    public function getCreateTImeAttr($v)
    {
        return date('Y-m-d H:i:s', $v);
    }
}